package com.JieCheng.controller;

/**
 * Created by Zhang on 2017/5/8.
 */
import com.JieCheng.dao.model.User;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;


@Controller
public class PageController extends BaseController{

    @ApiOperation(value="界面跳转", notes="跳转至登陆界面",httpMethod = "GET")
    @RequestMapping("/login")
    public String login(){
        return "login";
    }

    @ApiOperation(value="界面跳转", notes="跳转至学员中心",httpMethod = "GET")
    @RequestMapping("/studentCenter")
    public String studentcenter(){
        return "studentCenter";
    }

    @ApiOperation(value="界面跳转", notes="跳转至修改密码",httpMethod = "GET")
    @RequestMapping("/restartPassword")
    public String restartpassword(){
        return "restartPassword";
    }

    @ApiOperation(value="界面跳转", notes="跳转至用户管理",httpMethod = "GET")
    @RequestMapping("/userAdmin")
    public String useradmin(){
        return "userAdmin";
    }

    @ApiOperation(value="界面跳转", notes="跳转至题库管理",httpMethod = "GET")
    @RequestMapping("/topicAdmin")
    public String topicadmin(){
        return "topicAdmin";
    }

    @ApiOperation(value="检查用户", notes="根据登入者账号密码检查用户合法性，若存在则跳转至首页",httpMethod = "POST")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "loginName1", value = "登录名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "passWord1", value = "密码", required = true, dataType = "String"),
    })
    @RequestMapping("/admin")
    public String admin(HttpServletRequest httpServletRequest,Model model,
                        @RequestParam("loginName1") String loginName,@RequestParam("passWord1") String passWord){
        return userService.checkUser(loginName,passWord,"admin",model,httpServletRequest);
    }

    @ApiOperation(value="跳转界面", notes="根据登入者账号密码检查用户合法性，若存在则跳转至用户首页",httpMethod = "POST")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "loginName", value = "登录名", required = true, dataType = "String"),
            @ApiImplicitParam(name = "passWord", value = "密码", required = true, dataType = "String"),
    })
    @RequestMapping("/index")
    public String checkUser(HttpServletRequest httpServletRequest,Model model,
                            @RequestParam("loginName") String loginName,@RequestParam("passWord") String passWord){
        return userService.checkUser(loginName,passWord,"index",model,httpServletRequest);
    }

    @ApiOperation(value="界面跳转", notes="根据登入者账号密码检查用户合法性，若存在则跳转至首页",httpMethod = "POST")
    @ApiImplicitParams(value = {
            @ApiImplicitParam(name = "carexam", value = "科目几",defaultValue="1/2/3/4", required = true, dataType = "String"),
            @ApiImplicitParam(name = "cartype", value = "车型",defaultValue="C1/C2", required = true, dataType = "String"),
            @ApiImplicitParam(name = "examtype", value = "答题类型", required = true, dataType = "String")
    })
    @RequestMapping("/center")
    public String center(HttpServletRequest httpServletRequest,Model model,
                         @RequestParam("examtype") String examtype,@RequestParam("carexam") String carexam,@RequestParam("cartype") String cartype){
      return subjectService.centerPage(httpServletRequest,model,examtype,carexam,cartype);
    }
}
